<template>
	<!-- 请求待通过好友列表 -->
	<view>
		<view class="content">
			<view class="item" v-for="(item,index) in pendingList" :key='index'>
				<view class="">{{item.user | noMail}} 请求添加你为好友</view>
				<view class="">
					<button class="btn" type="primary" size="mini" @tap="btnClick(item,1,index)">通过</button>
					<button class="btn" type="warn" size="mini" @tap="btnClick(item,0,index)">拒绝</button>
				</view>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pendingList:[]
			}
		},
		onLoad(e){
			console.log(e)
			this.pendingList = JSON.parse(e.pendingList)
			console.log(this.pendingList)
			
		},
		filters:{
				noMail(val){
					if(val && val.includes('@')){
						return val.split('@')[0]	
					}else{
						return val
					}
						
				}
		},
		methods: {
			btnClick(item,f,index){
				console.log(item)
				//通过
				// `?id=${item.id}&user=${item.user}&flag=${f}`
				this.$api.pass_friend({
					id:item.id,
					user:item.user,
					flag:f
				}).then(res=>{
					this.$refs.uToast.show({
						title: res.msg,
						type: 'success',
						position: "top",
						duration: 1500
					})
				})
				this.noPassList.splice(index,1)
			},
			queyUserById(data){
				data.forEach(ele=>{
					this.$api.searchById(`?id=${ele}`).then(res=>{
						console.log(res)
						this.noPassList.push(res.data.data)
					})
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.content{
		width: 92%;
		margin: 0 auto;
		
	}
	.item{
		/* border: 1px solid; */
		padding: 25rpx 0;
		display: flex;
		justify-content: space-between;
		.btn{
			// border: 1px solid black;
			padding: 0 15rpx;
			margin: 0 10rpx;
			// background-color: ;
		}
	}
	.item:not(:last-of-type){
		border-bottom: 1px solid rgba(128,128,128,.2);
	}
</style>
